//
//  HPBalanceQueryViewController.m
//  ZZTong
//
//  Created by handpay on 13-5-10.
//  Copyright (c) 2013年 handpay. All rights reserved.
//

#import "HPBalanceQueryViewController.h"
#import "Utility.h"
#import "DefineUtil.h"
#import "CallbackData.h"
#import "ZZTongUtility.h"

@interface HPBalanceQueryViewController ()

@property (nonatomic, retain) CallbackData* callbackData;
@end

//#define kCellTitleLabelTag           10008
//#define kCellValueLabelTag           10009

#define kBankNameTag    0
#define kAccountTag     1
#define kBankTypeTag    2
#define kBalanceTag     3

@implementation HPBalanceQueryViewController

//@synthesize dataDic;
@synthesize callbackData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

//- (int)addElement:(UIView*)destView flag:(BOOL)flag label:(NSString*)label value:(NSString*)value top:(int)top{
//    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, top, 100, 30)];
//    [titleLabel setTag:kCellTitleLabelTag];
//    [titleLabel setBackgroundColor:[UIColor clearColor]];
//    [titleLabel setFont:kNormalFont];
//    [titleLabel setMinimumFontSize:14];
//    [titleLabel setTextColor:kNormalFontColor];
//    [titleLabel setText:label];
//    [destView addSubview:titleLabel];
//    [titleLabel release];
//    
//    //value
//    UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, top, 170, 30)];
//    [valueLabel setTextAlignment:NSTextAlignmentRight];
//    [valueLabel setTag:kCellValueLabelTag];
//    [valueLabel setBackgroundColor:[UIColor clearColor]];
//    [valueLabel setFont:kNormalFont];
//    if (flag) {
//        [valueLabel setTextColor:kGreenColor];
//    }else{
//        [valueLabel setTextColor:kNormalFontColor];
//    }
//    
//    [valueLabel setText:value];
//    [destView addSubview:valueLabel];
//    [valueLabel release];
//    
//    top += (30 + 5);
//    
//    if (flag) {
//        UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(10, top, 260, 1)];
//        lineView.backgroundColor = kGrayColor;
//        [destView addSubview:lineView];
//        [lineView release];
//        
//        top += 6;
//    }
//    return top;
//}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [ZZT_UIENG hideNavigationBar:NO];
//    [self hideTabBar:NO];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [ZZT_UIENG hideNavigationBar:NO];
}
- (void)viewDidLoad
{
    self.title = @"余额查询";
    [super viewDidLoad];
    self.canSave = NO;
    self.callbackData = [self.screenData objectForKey:@"callbackData"];
    
#if ZZT_FOR_TEST
    self.screenData = @{@"cardNo"   : @"6226 **** **** 2012",
                        @"balance"  : @"¥5000",
                        @"bankName" : @"民生银行",
                        @"bankType" : @"借记卡"};
#endif
    
    //
    
    self.bgTableView.dataSource = self;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [_btnNext release];
    self.callbackData = nil;
    [_bgTableView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setBtnNext:nil];
    [self setBgTableView:nil];
    [super viewDidUnload];
}

- (IBAction)buttonClick:(id)sender {
    [self.callbackData.target performSelector:self.callbackData.callback];
}
- (UITableViewCell *)initTableViewCell:(NSInteger)index{
    
    UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    
    UIImageView* iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 11, 22, 22)];
    
    UILabel* desLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 0, 100, 44)];
    desLabel.textColor = kNormalFontColor;
    desLabel.font = kNormalFont;
    desLabel.textAlignment = NSTextAlignmentLeft;
    
    UILabel* valueLabel = [[ UILabel alloc] initWithFrame:CGRectMake(150, 0, 155, 44)];
    valueLabel.textColor = kNormalFontColor;
    valueLabel.font = kNormalFont;
    valueLabel.textAlignment = NSTextAlignmentRight;
    
    switch (index) {
        case kBankNameTag:
        {
            NSString* bankName = [self.screenData objectForKey:@"bankName"];
            NSString* iconName = @"zh_tag.png";
            if (!bankName) {
                bankName = @"未知";
            }else{
                iconName = [ZZTUtility getBankLogoWithName:bankName];
            }
            if (!iconName) {
                iconName = @"zh_tag.png";
            }
            iconImageView.image = [UIImage imageNamed:iconName];
            desLabel.text = bankName;
            valueLabel.hidden = YES;
            break;
        }
        case kAccountTag:
            iconImageView.image = [UIImage imageNamed:@"zh_tag.png"];
            desLabel.text = @"账户";
            valueLabel.text = [Utility encryptCardID:[self.screenData objectForKey:@"cardNo"]];
            break;
        case kBankTypeTag:
            iconImageView.image = [UIImage imageNamed:@"card_type_tag.png"];
            desLabel.text = @"银行卡类型";
            NSString* bankType = [self.screenData objectForKey:@"bankType"];
            if (!bankType) {
                bankType = @"未知";
            }
            valueLabel.text = bankType;
            break;
        case kBalanceTag:
            iconImageView.image = [UIImage imageNamed:@"balance_tag.png"];
            desLabel.text = @"可用余额";
            valueLabel.text = [Utility getFormatMoneyAndSymbol:[self.screenData objectForKey:@"balance"]];
            valueLabel.textColor = kDarkGreenFontColor;
            valueLabel.font = kSecondBigFont;
            break;
        default:
            break;
    }
    [cell addSubview:iconImageView];
    [iconImageView release];
    
    [cell addSubview:desLabel];
    [desLabel release];
    
    [cell addSubview:valueLabel];
    
    return [cell autorelease];
}
#pragma UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self initTableViewCell:indexPath.row];
}
@end
